package com.mtw.bbs.fileAdmin.feign;


import com.mtw.bbs.common.core.vo.Result;
import com.mtw.bbs.common.web.interceptor.BaseFeignInterceptor;
import com.mtw.bbs.fileAdmin.pojo.vo.FileVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

import static com.mtw.bbs.common.core.constant.ApiPrefix.API_PREFIX_FILE;


/**
 * file Feign接口类
 */
@FeignClient(
        value = "bbs-file",
        contextId = "fileClientI",
        configuration = BaseFeignInterceptor.class,
        fallback = FileClient.FileClientFallback.class
)
public interface FileClient {


    @ApiOperation(value = "获取文件url", notes = "根据文件id查询文件url")
    @GetMapping(value = API_PREFIX_FILE+"/url")
    Result<FileVo> getUrl(@RequestParam("id") String id);



    @ApiOperation(value = "批量获取文件url", notes = "根据文件id数组查询文件url")
    @PostMapping(value = API_PREFIX_FILE+"/urls",headers = "Content-Type=application/json")
    Result<List<FileVo>> getFileUrlByIdArray(@RequestBody String[] ids);



    /**
     * Feign失败配置
     */
    @Component("fileClient")
    class FileClientFallback implements FileClient {


        @Override
        public Result<FileVo> getUrl(String id) {
            return Result.fail("获取失败");
        }

        @Override
        public Result<List<FileVo>> getFileUrlByIdArray(String[] ids) {
            return Result.fail("获取失败");
        }
    }

}
